#!/bin/bash
# Those script just for centos7(Recommend), you need to correct it on your platform install step.
# Holp you could share other platform setup script.

make_sure_dir_exist () { [ -d $1 ] || mkdir -p $1;}

# install docker and docker-compose
# install python http://www.liquidweb.com/kb/how-to-install-pip-on-centos-7
sudo rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
sudo yum -y update
sudo yum install -y docker
sudo yum -y install python-pip
sudo yum install -y docker-compose

# open the firewall port for http
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload

# setup the main nginx redirect http request into docker, the pyweb default port is 10080, something like:
# location / {
#     proxy_redirect        off;
#     proxy_pass      http://127.0.0.1:10080;
#     proxy_set_header   Host             $host;
#     proxy_set_header   X-Real-IP        $remote_addr;
#     proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
# }
sudo yum install -y nginx

# make sure volumes dir is exist
make_sure_dir_exist "pyweb/log/"
make_sure_dir_exist "postgresql/log"
make_sure_dir_exist "postgresql/data"

# fabric for local update to the server
# sudo pip install fabric
# cmd: fab --set host=root@x.x.x.x:x,pwd=x,git=https://git.oschina.net/xfuture/pyweb-docker.git update_app_on_server
